<template>
  <div class="index-container">
    <div class="main-header clearfix">
      <el-row>
       <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
          <!-- <el-button type="primary"  icon="el-icon-plus" class="sureBtn"  size="medium"  @click="handleAdd" > 新 增 类 型</el-button> -->
          <span style="color: transparent;">1</span>
        </el-col>
        <el-col :xs="16" :sm="16" :md="16" :lg="16" :xl="16">
          <div class="search fr">
            <div>
              <el-input  v-model="selectForm.name"   size="medium"  placeholder="老人姓名"></el-input>
            </div>
            <div>
              <el-select v-model="selectForm.team_id" clearable placeholder="负责站点" filterable size="medium"  style="width: 100%;">
                <el-option
                  v-for="item in teamList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </div>
            <el-button size="medium"   type="primary"   icon="el-icon-search"  class="fr"    @click="handleSearch" > 搜索</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="main-content" style="height: calc(100vh - 250px);">
      <main-table
        :columns="tableColumns"
        :data="tableList"
        :loading="loading"
        :pagination="pagination"
         @getData="fetchTableList"
        wrapperHeight="calc(100% - 73px)" height="100%"
      >
      <el-table-column slot="action" fixed="right" label="操作" width="150">
        <template slot-scope="scope">
          <el-button type="text" class="button-view-color" @click="views(scope.row)"><i class="fa fa-search" aria-hidden="true"></i> 查看任务详情</el-button>
        </template>
      </el-table-column>
      </main-table>
    </div>
    <!--查看详情弹窗-->
    <el-dialog
      title="任务信息"
      :visible.sync="dialogVisible"
      width="800px">
      <order-info @cancle="dialogVisible = false" :close-on-click-modal="false" :data="ruleForm" @load="handleSearch"></order-info>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  import mainTable from "@/components/main-table/index";
  import * as APITasklog from '@/api/tasklog'
  import * as APIWangge from "@/api/wangge";
  import * as APIOrder from '@/api/order'
  import { unixToDate } from "@/utils"
  import orderInfo from './components/order-info'
  export default {
    name: "doorserve-serve-team-task",
    components: {
      mainTable,
      orderInfo
    },
    filters: {
      getTotal (row) {
        return Number(row.num0) + Number(row.num1) + Number(row.num2) + Number(row.num3) + Number(row.funum1) + Number(row.funum2)
      }
    },
    data() {
      return {
        // 日期设置
        pickerOptions: {
          disabledDate (time) {
            return time.getTime() > Date.now()
          }
        },
        loading: false,
        title: '添加图标',
        dialogVisible: false,
        ruleForm: {},
        currentSelectedData: [],
        pageData: {},
        selectForm: {
          page:1
        },
        tableList:[],
        pagination: {
          current: 1,
          size: 10,
          total: 0
        },
        tableColumns: [
         {
           index: true,
           fixed: true
         },
         {
           prop: 'member_name',
           label: '评论人',
           fixed: true
         },
         {
           prop: 'content',
           label: '评论内容'
         },
         {
           prop: 'team_name',
           label: '任务站点'
         },
         {
           prop: 'servicer_name',
           label: '服务人姓名'
         },
         {
           prop: 'older_name',
           label: '老人姓名'
         },
         {
           prop: 'address',
           label: '老人住址',
           minWidth: 300
         },
         {
           prop: 'create_time',
           label: '提交时间',
           width: 160,
           formatter (row, column, cellValue) {
             return unixToDate(cellValue)
           }
         },
         {
           slot: 'action'
         }
        ],
        key: Math.random(),
        teamList:[]
      };
    },
    created() {},
    beforeDestroy() {},
    mounted() {
      this.fetchTableList();
      this.teamIndex();
    },
    methods: {
      // 站点列表
      teamIndex () {
        APIWangge.teamList({ page_size: 100 }).then(res => {
          this.teamList = res['data']['list']
        })
      },
      handleSearch() {
        this.pagination = {
          current: 1,
          size: 10,
          total: 0
        }
        this.fetchTableList({ page: 1 })
      },
      fetchTableList(pageObj) {
        this.loading = true;
        let data = {
          ...this.selectForm,
          ...pageObj
        }
        APIOrder.orderFeed(data).then((resp) => {
          if (resp.code === 200) {
            const { list = [], total = 0 } = resp.data;
            this.tableList = list || []
            this.pagination.total = total;
          }
        }).finally(() => {
          this.loading = false
        });
      },
      // 查看详情
      views (row) {
        APIOrder.orderInfo({ id: row.order_id }).then((res) => {
          this.dialogVisible = true
          this.data = { ...res.data.info }
        })
      }
    },
  };
</script>
<style lang="scss" scoped>
  .index-container {
    box-sizing: border-box;
    width: 100%;
    padding: 0 30px !important;
    margin: 0 !important;
    background: #fff !important;

    .main-header {
      padding-top: 4px;
      margin-bottom: 24px;

      .search {
        display: inline-block;

        .search-title {
          flex: 0 0 48px;
          width: 48px;
          font-size: 16px;
          line-height: 36px;
          color: #333;
        }
      }

      .search > div {
        display: inline-block;
        margin-left: 20px;
      }
    }
    .task-icon-img{
      width: 80px;
      height: 80px;
    }
  }

  .form-footer {
    padding-left: 100px;
  }

  .dialog-main {
    .table-do {
      margin-bottom: 15px;
    }

    ::v-deep {
      th {
        .cell {
          color: #fff;
        }
      }
    }
  }
</style>
